import time
from selenium import webdriver  # 导入包
from selenium.webdriver.common.by import By

# 声明浏览器对象
chrome = webdriver.Chrome()

chrome.get('https://www.baidu.com/')  # 打开一个网站
time.sleep(2)

# 获取单元素
# print(chrome.page_source)  # 获取该链接源代码
# ipt1 = chrome.find_element(By.ID, 'kw')
# ipt2 = chrome.find_element(By.CSS_SELECTOR, '#head_wrapper #kw')
# ipt3 = chrome.find_element(By.XPATH, '//*[@id="kw"]')  # 右键选择copy copyXpath

# 获取多个元素
# lst = chrome.find_elements(By.CLASS_NAME, 'title-content-title')  # 将查询到的对象打包成列表返回
# print(lst)
# # 循环输出每个列表的text
# for i in lst:
#     print(i.text)

# ipt = chrome.find_element(By.ID, 'kw')
# btn = chrome.find_element(By.ID, 'su')
# ipt.send_keys('Selenium')
# time.sleep(1)
# btn.click()
# time.sleep(2)
# chrome.close()